<template>
  <div class="items-box">
    <div class="head-part">
      <div class="title">
        <span>{{ title }}</span>
      </div>
      <div class="value-box">
        <div class="title">全省</div>
        <div class="value">{{ value }}</div>
      </div>
      <van-popover
        v-model:show="showPopover"
        :actions="actions"
        @select="onSelect"
      >
        <template #reference>
          <div class="qs-text">
            {{ selectName }} <van-icon name="arrow-down" />
          </div>
        </template>
      </van-popover>
    </div>

    <div class="desc-panel">
      <div class="right-box">
        <div class="right-desc">
          环比<span style="color: #10cfa5">+0.18%</span>
        </div>
      </div>
    </div>

    <lineEcharts :chartObj="chartObj" :cindex="mindex" x="left" y="top" />
  </div>
</template>
<script>
import { reactive, toRefs, onMounted } from "vue";
import lineEcharts from "@/components/lineBarEcharts.vue";
export default {
  components: {
    lineEcharts,
  },
  props: ["itemObj"],
  setup(props, { emit }) {
    let itemObj = props.itemObj;
    const state = reactive({
      showPopover: false,
      selectName: "全省趋势",
      title: itemObj.title,
      value: itemObj.value,
      actions: [{ text: "全省趋势" }, { text: "分公司排名" }],
      tabList: itemObj.tabList,
      dataItem: props.itemObj,
      tabIndex: 0,
      monthSatisfaction: "4131",
      mindex: itemObj.index1,
      chartObj: {},
    });
    //一级tab切换
    function tabClick(val) {
      state.tabIndex = val;
      emit("changeMsg", state.tabList[val]);
      if (val == 0) {
        state.monthSatisfaction = "92.24%";
        state.ranking = "24";
      } else {
        state.monthSatisfaction = "96.24%";
        state.ranking = "10";
      }
    }
    const onSelect = (action) => {
      state.selectName = action.text;
      if (state.selectName == "分公司排名") {
      } else {
      }
    };
    onMounted(() => {
      state.chartObj = state.dataItem.chartObj;
    });
    return {
      ...toRefs(state),
      tabClick,
      onSelect,
    };
  },
};
</script>
<style lang="scss" scoped>
.items-box {
  width: 100%;
  background-color: #fff;
  border-radius: 5px;
  position: relative;
  .head-part {
    margin-top: 10px;
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    .qs-text {
      padding: 0 15px;
      line-height: 24px;
      color: #666666;
      margin-right: 10px;
      font-size: 12px;
      background: #ffffff;
      box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
    }
  }
  .title {
    // width: 30%;
    display: flex;
    align-items: center;
    span {
      font-size: 16px;
      font-weight: 400;
      color: #333333;
    }
  }

  .value-box {
    display: flex;
    align-items: center;

    .title {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
    }

    .value {
      margin-left: 5px;
      font-size: 21px;
      font-family: Helvetica-Bold, Helvetica;
      font-weight: bold;
      color: #333333;
    }
  }
  .desc-panel {
    position: absolute;
    top: 30px;
    left: 0px;
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: end;
    z-index: 999;
    .left-desc {
      font-size: 14px;
      .text1 {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        margin-right: 6px;
      }
      .text2 {
        font-size: 21px;
        font-weight: bold;
        color: #333333;
        margin-right: 6px;
      }
    }

    .right-box {
      display: flex;
      margin-right: 10px;

      .right-desc1 {
        padding: 0 10px;
        height: 24px;
        line-height: 24px;
        background: #f3f3f3;
        color: #333333;
        border-radius: 4px;
        font-size: 12px;
        text-align: center;
      }

      .right-desc {
        padding: 0 10px;
        height: 24px;
        line-height: 24px;
        background: #fff0dc;
        color: #333333;
        border-radius: 4px;
        font-size: 12px;
        text-align: center;
      }
    }
  }
}
</style>
